import cn.entity.Page;
import cn.entity.User;
import cn.service.UserServiceImpl;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class test {
    @Test
    public void test(){
        Page page = new Page();
        User user = new User();
      //  user.setName("aa");
        page.setUser(user);
        page.setCurPage(2);
        page.setPerNum(5);
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring/spring-mybatis.xml");
        UserServiceImpl userDaoService = applicationContext.getBean("userDaoService",UserServiceImpl.class);
        List<User> userList = userDaoService.getUserList(page);
        for (User user1:userList){
            System.out.println(user1.getName());
        }
    }
    @Test
    public void test2(){


        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring/spring-mybatis.xml");
        UserServiceImpl userDaoService = applicationContext.getBean("userDaoService",UserServiceImpl.class);
        User user1 = new User();
        user1.setName("aa");
        int ss = userDaoService.getUserNum(user1);
        System.out.println(ss);
    }
  @Test
    public void test3(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring/spring-mybatis.xml");
        UserServiceImpl userDaoService = applicationContext.getBean("userService",UserServiceImpl.class);
        User user1 = new User();
        user1.setName("111");
        user1.setPassword("111");
        user1.setEmail("111");
        user1.setPhone("111");
        boolean b = userDaoService.addUser(user1);
        System.out.println(b);
    }

    @Test
    public void test4(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring/spring-mybatis.xml");
        UserServiceImpl userDaoService = applicationContext.getBean("userService",UserServiceImpl.class);
        User user1 = new User();
        user1.setId(1);

        User user = userDaoService.getUserbyId(user1);
        System.out.println(user.getName()+"::::"+user.getName());
    }

    @Test
    public void test5(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring/spring-mybatis.xml");
        UserServiceImpl userDaoService = applicationContext.getBean("userService",UserServiceImpl.class);
        User user1 = new User();
        user1.setId(1);
        boolean b  = userDaoService.deleterUser(user1);
        System.out.println(b);
    }

}
